package cn.edu.dao.impl;

import cn.edu.dao.BookDao;
import cn.edu.pojo.Book;

import java.util.List;

public class BookDaoImpl extends BaseDao implements BookDao {

    @Override
    public Book queryBookBySn(String sn) {
        String sql = "select sn,bname,publish,author,price from book where sn =?";
        return queryForOne(Book.class,sql,sn);
    }

    @Override
    public List<Book> queryBook() {
        String sql = "select sn,bname,publish,author,price from book";
        return queryForList(Book.class,sql);
    }

    @Override
    public List<Book> queryBookBylike(String bname) {
        String sql = "select sn,bname,publish,author,price from book where bname like "+"'%"+bname+"%'";
        return queryForList(Book.class,sql);
    }

    @Override
    public int addBook(Book book) {
        String sql = "insert into Book(sn,bname,author,price,publish) values(?,?,?,?,?)";
        return update(sql,book.getSn(),book.getBname(),book.getAuthor(),book.getPrice(),book.getPublish());
    }

    @Override
    public int deleteBookbySn(String sn) {
        String sql = "delete from book where sn=?";
        return update(sql,sn);
    }

    @Override
    public int upDateBook(Book book) {
        String sql="update book set bname=?,publish=?,price=?,author=? where sn=?";
        return update(sql,book.getBname(),book.getPublish(),book.getPrice(),book.getAuthor(),book.getSn());
    }
}
